package com.wbcs.system.component.application.report.configbean.editablereport.transaction;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import com.wbcs.system.ReportRequest;
import com.wbcs.system.component.application.report.configbean.editablereport.EditActionGroupBean;

public class TransactionTypeWrapper
{
    private static Log log=LogFactory.getLog(TransactionTypeWrapper.class);
    
    private ITransactionType transObj;

    private boolean isStartTrans;

    private boolean isCommited;

    private boolean isRollback;

    public TransactionTypeWrapper(ITransactionType transObj)
    {
        this.transObj=transObj;
    }
    
    public boolean isStartTrans()
    {
        return isStartTrans;
    }

    public boolean isCommited()
    {
        return isCommited;
    }

    public boolean isRollback()
    {
        return isRollback;
    }

    public void beginTransaction(ReportRequest rrequest,List<EditActionGroupBean> lstEditActionGroupBeans)
    {
        if(isStartTrans) return;
        isStartTrans=true;
        transObj.beginTransaction(rrequest,lstEditActionGroupBeans);
    }

    public void commitTransaction(ReportRequest rrequest,List<EditActionGroupBean> lstEditActionGroupBeans)
    {
        if(!isStartTrans)
        {
            log.warn("不能提交页面"+rrequest.getPagebean().getId()+"上保存操作，因为还没有启动事务");
            return;
        }
        if(isCommited||isRollback) return;
        isCommited=true;
        transObj.commitTransaction(rrequest,lstEditActionGroupBeans);
    }

    public void rollbackTransaction(ReportRequest rrequest,List<EditActionGroupBean> lstEditActionGroupBeans)
    {
        if(!isStartTrans)
        {
            log.warn("不能回滚页面"+rrequest.getPagebean().getId()+"上保存操作，因为还没有启动事务");
            return;
        }
        if(isRollback||isCommited) return;
        isRollback=true;
        transObj.rollbackTransaction(rrequest,lstEditActionGroupBeans);
    }
}

